<?php
declare(strict_types=1);

namespace App\Controller;

use App\Common\Response\SystemCode;
use App\Model\AuthRole;
use App\Model\Module;
use App\Model\Playlet;
use App\Model\Tag;
use App\Model\Company;
class BaseController
{

    public static $commonStatus = [
        '0'       => '禁用',
        '1'       => '正常',
        '2'       => '未启用',
        '3'       => '重置密码',
    ];

    public function response($code, $msg = '', $data = '')
    {
        if (is_array($msg)) {
            $msg = implode(' ', array_column($msg, 0));
        }

        return [
            'code'    => $code,
            'data'    => $data,
            'message' => $msg,
        ];
    }

    public function module(){

        return $this->response(SystemCode::SYSTEM_SUCCESS, '获取成功',Module::select(['id as value','name','label'])->get());
    }
    public function AuthRole(){

        return $this->response(SystemCode::SYSTEM_SUCCESS, '获取成功',AuthRole::select(['id as value','name as label'])->where(['status' => AuthRole::STATUS_SHOW])->get());
    }
    public function company(){

        return $this->response(SystemCode::SYSTEM_SUCCESS, '获取成功',Company::select(['id as value','name as label'])->where(['status' => Company::STATUS_SHOW])->get());
    }

    public function playlet(){

        return $this->response(SystemCode::SYSTEM_SUCCESS, '获取成功',Playlet::select(['id as value','name as label'])->where(['status' => Playlet::STATUS_SHOW])->get());
    }

    public function ParentTag(){

        return $this->response(SystemCode::SYSTEM_SUCCESS, '获取成功',Tag::select(['id as value','name as label'])->where(['parent_id' =>0])->get());
    }
}